import { Injectable } from '@angular/core';
import { Observable } from "rxjs/Observable";
import { Subject } from "rxjs/Subject";

export interface ModalParams {
  isDynamic?: boolean;
  moduleId?: any;
  templateUrl?: string;
  closeObserver: Subject<any>;
  data: any;
}

@Injectable()
export class CmModalService {
  index = 0;
  cbs = [];
  toCreate: Subject<any>; //给ModalContainer发送新建实例；

  constructor() {
    this.toCreate = new Subject();
  }

  showModal(data, isDynamic = false, templateUrl?, moduleId?) {
    let closeObserver = new Subject();
    this.toCreate.next({
      isDynamic,
      closeObserver,
      data,
      tips: data.tips,
      moduleId,
      templateUrl
    });
    return closeObserver;
  }

}